import request from '@/utils/request'

import md5 from 'js-md5'
import { AESencrypt } from '@/utils/mima'
export function login(params) {
  // params.pwd = md5(params.pwd)
  params.pwd = AESencrypt(params.pwd)
  return request({
    url: '/sys/Login',
    method: 'post',
    params
  })
}

export function GetToken() {
  return request({
    url: '/sys/GetToken',
    method: 'post'
  })
}
export function getInfo() {
  return request({
    url: '/sys/UserInfo',
    method: 'post'
  })
}

export function NumberVerifyCode() {
  return request({
    url: '/sys/NumberVerifyCode',
    method: 'get'
  })
}

/**是否需要短信验证码 */
export function CheckLogin(params) {
  return request({
    url: '/sys/CheckLogin',
    method: 'post',
    params
  })
}

/**发送短信验证码 */
export function SendCode_Phone(params) {
  return request({
    url: '/sys/SendCode_Phone',
    method: 'post',
    params
  })
}

export function logout() {
  return request({
    url: '/sys/Exit',
    method: 'post'
  })
}

export function MyAuth() {
  return request({
    url: '/sys/MyAuth',
    method: 'post'
  })
}

export function ClearCache() {
  return request({
    url: '/sys/ClearCache',
    method: 'post'
  })
}

// 菜单模块管理
export function GetPage_Auth(params) {
  return request({
    url: '/sys/GetPage_Auth',
    method: 'post',
    params
  })
}

export function AddEdit_Auth(data) {
  return request({
    url: '/sys/AddEdit_Auth',
    method: 'post',
    data
  })
}

export function Delete_Auth(data) {
  return request({
    url: '/sys/Delete_Auth',
    method: 'post',
    data
  })
}

export function SetValid_Auth(params) {
  return request({
    url: '/sys/SetValid_Auth',
    method: 'post',
    params
  })
}

// 角色管理
export function GetPage_Role(params) {
  return request({
    url: '/sys/GetPage_Role',
    method: 'post',
    params
  })
}

export function Delete_Role(data) {
  return request({
    url: '/sys/Delete_Role',
    method: 'post',
    data
  })
}

export function AddEdit_Role(data) {
  return request({
    url: '/sys/AddEdit_Role',
    method: 'post',
    data
  })
}
// 获取当前角色已有权限
export function GetPage_RoleAuth(params) {
  return request({
    url: '/sys/GetPage_RoleAuth',
    method: 'post',
    params
  })
}
export function Set_RoleAuth(params, data) {
  return request({
    url: '/sys/Set_RoleAuth',
    method: 'post',
    params,
    data
  })
}

// 系统用户

// 启用停用
export function SetValid_SysUsers(params) {
  return request({
    url: '/sys/SetValid_SysUsers',
    method: 'post',
    params
  })
}

export function GetPage_SysUsers(params) {
  return request({
    url: '/sys/GetPage_SysUsers',
    method: 'post',
    params
  })
}
export function AddEdit_SysUsers(data,type) {
  // 如果是新增  密码加密
  // if(type == '1'){
  //   data.password = data.password ? AESencrypt(data.password) : ''
  // }
  return request({
    url: '/sys/AddEdit_SysUsers',
    method: 'post',
    data
  })
}

export function Delete_Users(data) {
  return request({
    url: '/sys/Delete_Users',
    method: 'post',
    data
  })
}
// 设置密码
export function SetPwd(params) {
  // params.pwd = md5(params.pwd)
  params.pwd = AESencrypt(params.pwd)
  return request({
    url: '/sys/SetPwd',
    method: 'post',
    params
  })
}
//设置密码
export function SetMyPwd(params) {
  params.pwd = AESencrypt(params.pwd)
  return request({
    url: '/sys/SetMyPwd',
    method: 'post',
    params
  })
}

export function GetSysUserLogs(params) {
  return request({
    url: '/sys/GetSysUserLogs',
    method: 'post',
    params
  })
}
